<template>
    <span>
        <template v-if="action == 'edit'">
            <el-switch
                    @click.native="quickChange"
                    v-on="$listeners"
                    v-model="myValue">
            </el-switch>
        </template>
        <template v-if="action == 'table'">
            <el-switch
                    @change="quickChange"
                    v-model="myValue">
            </el-switch>
        </template>
        <template v-if="action == 'search'">
              <el-select style="width:100%" @change="quickChangeOption" v-model="myValue" :placeholder="fieldName">
                <el-option
                        v-on="$listeners"
                        v-for="item in options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                </el-option>
            </el-select>
        </template>
    </span>
</template>
<script>
    import base from './base.js';

    export default {
        extends: base,
        props: {},
        data() {
            return {
                options: [{
                    value: '1',
                    label: '是'
                }, {
                    value: '0',
                    label: '否'
                }],
                searchModel: 'like',
            }
        },
        created() {
            if(this.action !== 'search'){
                this.myValue = Boolean(this.value);
            }
            else {
                this.options.unshift({
                    value: 'all',
                    label: '全部' + this.fieldName
                })
            }
        },
        watch: {
            value: function (newQuery) {
                if(this.action !== 'search'){
                    this.myValue = Boolean(newQuery);
                }
            }
        },
        methods:{
            quickChangeOption(val) {
                // if (val == 'all') {
                //     this.myValue = null;
                // }
                // this.$emit('checkboxChange', this.myValue);
            }
        }
    }
</script>
<style>
</style>
